package com.hk.controller;

import com.hk.Enume.OperationType;
import com.hk.annotation.AotoFile;
import com.hk.constant.LogConstaant;
import com.hk.core.PageResult;
import com.hk.core.R;
import com.hk.core.Result;
import com.hk.domain.Business;
import com.hk.domain.TalkHistory;
import com.hk.dto.BusinessFalsePageDto;
import com.hk.dto.BusinessPageDto;
import com.hk.dto.BusinessUpdateDto;
import com.hk.dto.PullDto;
import com.hk.service.BusinessService;
import com.hk.vo.TalkHistoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business")
public class BusinessController {
    @Autowired
    BusinessService businessService;

    //商机列表展示
    @GetMapping("/list")
    public PageResult list(BusinessPageDto dto){
       PageResult res=businessService.list(dto);
       return res;
    }

    //商机添加
    @AotoFile(value = OperationType.POST,title = LogConstaant.BUSINESS_LOG)
    @PostMapping
    public R add(@RequestBody Business business){
        businessService.add(business);
        return R.ok();
    }

    //根据id查看商机
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id){
     Business business=businessService.queryById(id);
     return Result.success(business);
    }

    //根据id查看沟通历史
    @GetMapping("/record/list")
    public Result queryTalkById(Integer businessId){
       List<TalkHistoryVo> res = businessService.queryTalkById(businessId);
        return Result.success(res);
    }

    //修改商机内容
    @AotoFile(value = OperationType.PUT,title = LogConstaant.BUSINESS_LOG)
    @PostMapping("/record")
    public R update(@RequestBody BusinessUpdateDto dto){
        businessService.update(dto);
        return R.ok();
    }

    //把商机扔到公海池
    @AotoFile(value = OperationType.PUT,title = LogConstaant.BUSINESS_LOG)
    @PutMapping("/back/{businessId}/{id}")
    public R push(@PathVariable Integer businessId,@PathVariable Integer id){
     int n=businessService.push(businessId,id);
        return R.ok(n);
    }

    /**
     * 在公海池显示伪商机
     */
    @GetMapping("/pool")
    public PageResult listFalse(BusinessFalsePageDto dto){
      PageResult res=businessService.listFalse(dto);
        return res;
    }

    /**
     * 公海池捞取数据
     */
    @AotoFile(value = OperationType.PUT,title = LogConstaant.BUSINESS_LOG)
    @PutMapping("/gain")
    public R pull(@RequestBody PullDto dto){
        businessService.pull(dto);
        return R.ok();
    }

}
